package com.tree.jvm.classloading;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;

/**
 * package com.tree.jvm.classloading
 * description:
 *
 * 被动使用类字段演示三：
 * 常量在编译阶段会存入调用类的常量池中，本质上没有直接引用到定义常量的类，对常量的引用实际被转化为类对常量池的引用。
 * 因此不会触发定义常量的类的初始化
 * @author tree
 * @date 2019-11-12 11:16
 */
public class Test3 {
    public static void main(String[] args) throws Exception {
        System.out.println(ConstClass.HELLOWORLD);


        CountDownLatch countDownLatch = new CountDownLatch(50);
        List<Thread> l = new ArrayList();
        for(int i =0; i< 500; i++){
            final int n = i;

            Thread t = new Thread(()->{
                try {
                    Thread.sleep(500);
                    System.out.println("======"+n);
                    countDownLatch.countDown();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
            t.start();
            l.add(t);

        }
//        l.forEach(t->{
//            try {
//                t.join();
//            } catch (InterruptedException e) {
//                e.printStackTrace();
//            }
//        });
        countDownLatch.await();
//        Thread.sleep(1000000);
        System.out.println(111111);
    }
}
class ConstClass{
    static {
        System.out.println("ConstClass init !");
    }


    public static final String HELLOWORLD = "hello world";
}
